package com.example.springmvcdemo;
//接收Cookie

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/Cookie1")
@RestController
public class CookieReq {
    @RequestMapping("/CookieReq")
    public String cookieReq(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();//将接收到的请求转换为Cookie数组
        if (cookies !=null){
            System.out.println("收到的Cookie为:");
            for (Cookie cookie:cookies){
                System.out.println("Key:"+cookie.getName());
                System.out.println("value:"+cookie.getValue());
                //接收到的 Cookie 不能是汉字!!!,必须要符合 ASCLL码
            }
        }
        return "接收Cookie成功";
    }
}
